package com.nk.system.servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.nk.system.beans.ToptenBean;
import com.nk.system.service.MainService;

/**
 * Servlet implementation class BachelorServlet2
 */
public class BachelorServlet2 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	@Autowired
	private MainService mainService;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BachelorServlet2() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		initial(request, response);
		return;
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		initial(request, response);
		return;
	}
	
	private void initial(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
		
		WebApplicationContext con = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());
		mainService = (MainService)con.getBean("mainService");
		
		List<ToptenBean> name = mainService.getUname(2);
		request.setAttribute("nameList", name);
		
		request.getRequestDispatcher("mainBachelor.jsp").forward(request, response);
		return;
		
	}

}
